package de.koller.hydrogen.engine;

import de.koller.hydrogen.HNode;
import de.koller.hydrogen.engine.physics.HPhysics;
import de.koller.hydrogen.engine.player.Player;
import de.koller.oceanFramework.tree.Child;
import de.koller.oceanFramework.util.ColorIntUtil;
import de.koller.oceanFramework.util.OceanSet;
import java.util.Random;

public class HEngine extends HNode {

	public Player selected = null;
			
	public final OceanSet<Player> players = new OceanSet<>();
	@Child public final HPhysics physics = new HPhysics();

	@Override
	protected void init() {
		super.init();
		
		setupPlayer();
	}
	
	private void setupPlayer() {	
		Random rnd = new Random();
		for( int i = 0; i < 25; i++ ) {
			Player p = new Player();
			p.add( hroot );
			
			p.mo.location.position.x = rnd.nextFloat() * 500 - 250;
			p.mo.location.position.y = rnd.nextFloat() * 500 - 250;
			p.color = ColorIntUtil.getIntColor( 0xff, 
						rnd.nextInt( 0xff ), 
						rnd.nextInt( 0xff ), 
						rnd.nextInt( 0xff ) );
			
			selected = p;
		}
	}
	
	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
		players.update();
		
		for( Player p : players )
			physics.step( p.mo, elapsedTime );
	}
	
}
